package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书...");
        if(bookList.isFull()) {
            System.out.println("图书已满...");
        }
        Scanner in = new Scanner(System.in);

        System.out.println("请输入书名：");
        String name = in.nextLine();
        Book tmp;
        if((tmp = bookList.findBookOfName(name)) != null) {
            System.out.println("已有相同的图书：" + tmp);
            return;
        }

        System.out.println("请输入作者：");
        String author = in.nextLine();
        System.out.println("请输入价格：");
        int price = in.nextInt();
        System.out.println("请输入类型：");
        String type = in.nextLine();

        Book book = new Book(name, author, price, type);
        bookList.addBook(book);
        System.out.println("插入成功！！！");
    }
}
